package com.thoughtworks.impersonator.http.technorati;

import static com.thoughtworks.impersonator.http.IntegrationTestUtils.get;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

import java.io.File;


import org.junit.Test;

import com.thoughtworks.impersonator.http.record.Recorder;
import com.thoughtworks.impersonator.http.replay.Impersonator;

public class TechnoratiTest {
    @Test
    public void shouldWorkWithTechnorati() throws Exception {
        File storageDir = new File("target/tmp");
        TechnoratiRequestIdentifier technoratiRequestIdentifier = new TechnoratiRequestIdentifier();

        Recorder recorder = new Recorder(9999, "api.technorati.com", 80, storageDir, technoratiRequestIdentifier);
        String realServiceResult = get("http://localhost:9999/search?key=36c6e7f7005da3be4de6a8554289716a&query=impersonator");
        recorder.stop();

        Impersonator impersonator = new Impersonator(8888, storageDir, technoratiRequestIdentifier);
        String impersonatedResult = get("http://localhost:8888/search?key=36c6e7f7005da3be4de6a8554289716a&query=impersonator");
        impersonator.stop();

        assertThat(impersonatedResult, is(realServiceResult));
    }
}
